<?php
// 
//  security_model.php
//  ColdXin_CI
//  
//  Created by Will_Lee on 2011-05-01.
//  Copyright 2011 lishuzu. All rights reserved.
// 
 class Security_model extends CI_Model{
	function __construct(){
		parent::__construct();
		$this->userinfo = $this->session->userdata('userinfo') ? $this->session->userdata('userinfo') : '';
	}
	//是否登录
 	function isLogin(){
		if ($this->session->userdata('userinfo')) {
			return true;
		}else {
			return false;
		}
	}
	//是否登录
 	function isAdminLogin(){
		$userinfo = $this->session->userdata('adminuserinfo');
		$md5_username = substr(md5($this->config->item('adminuser')), 0, 24);
		$md5_password = substr(md5($this->config->item('adminpwd')), 0, 24);
		if ($userinfo['username'] == $md5_username && $userinfo['password'] == $md5_password) {
			return true;
		}else {
			return false;
		}
	}
	
	//更新用户信息
	function update_user_session(){
		if ($this->userinfo) {
			$this->load->model('user_model');
			$userinfo = $this->user_model->get_user($this->userinfo['uid']);
			if ($userinfo) {
				$session_data = array(
					'userinfo' => $userinfo,
					);
				$this->session->unset_userdata('userinfo');
				$this->session->set_userdata($session_data);
				return true;
			}
		}
		return false;
	}
}
?>